﻿using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace VueAdminService.Attributes
{
	public class TokenRequiredFilter : IOperationFilter
	{
		public void Apply(OpenApiOperation operation, OperationFilterContext context)
		{
			if (context.ApiDescription.RelativePath == "api/user/verifycode" || context.ApiDescription.RelativePath == "api/user/login")
			{
				return;
			}
			else
			{
				if (operation.Parameters == null)
					operation.Parameters = new List<OpenApiParameter>();
				operation.Parameters.Add(new OpenApiParameter()
				{
					Name = "token",
					In = ParameterLocation.Header,
					Required = true
				});
			}
		}
	}
}
